<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台（PHP版）
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码，建议反馈是我们前进的动力
// | 开源版本可自由商用，可去除界面版权logo
// | gitee下载：https://gitee.com/likeshop_gitee/likeadmin
// | github下载：https://github.com/likeshop-github/likeadmin
// | 访问官网：https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------


namespace app\api\controller;


use app\api\lists\TransactionRecordLists;
use app\api\logic\TransactionRecordLogic;
use app\api\validate\TransactionRecordValidate;
use app\common\model\user\User;
use think\facade\Config;


/**
 * transaction控制器
 * Class TransactionRecordController
 * @package app\api\controller
 */
class TransactionRecordController extends BaseApiController
{


    /**
     * @notes 获取transaction列表
     * @return \think\response\Json
     * @author likeadmin
     * @date 2025/04/09 14:11
     */
    public function lists()
    {
        if (isset($_GET['export']) && $_GET['export'] == 2) {
            if (!isset($_GET['secure_password'])) {
                return $this->fail('交易密码不能为空');
            }

            $user = User::findOrEmpty($this->userInfo['user_id']);
            if ($user->isEmpty()) {
                return $this->fail('用户不存在');
            }
            $passwordSalt = Config::get('project.unique_identification');
            $oldPassword = create_password($_GET['secure_password'], $passwordSalt);
            if ($oldPassword != $user['secure_password']) {
                return $this->fail('交易密码不正确');
            }
        }
        return $this->dataLists(new TransactionRecordLists());
    }


    /**
     * @notes 添加transaction
     * @return \think\response\Json
     * @author likeadmin
     * @date 2025/04/09 14:11
     */
    public function add()
    {
        $params = (new TransactionRecordValidate())->post()->goCheck('add');
        $result = TransactionRecordLogic::add($params);
        if (true === $result) {
            return $this->success('添加成功', [], 1, 1);
        }
        return $this->fail(TransactionRecordLogic::getError());
    }


    /**
     * @notes 编辑transaction
     * @return \think\response\Json
     * @author likeadmin
     * @date 2025/04/09 14:11
     */
    public function edit()
    {
        $params = (new TransactionRecordValidate())->post()->goCheck('edit');
        $result = TransactionRecordLogic::edit($params);
        if (true === $result) {
            return $this->success('编辑成功', [], 1, 1);
        }
        return $this->fail(TransactionRecordLogic::getError());
    }


    /**
     * @notes 删除transaction
     * @return \think\response\Json
     * @author likeadmin
     * @date 2025/04/09 14:11
     */
    public function delete()
    {
        $params = (new TransactionRecordValidate())->post()->goCheck('delete');
        TransactionRecordLogic::delete($params);
        return $this->success('删除成功', [], 1, 1);
    }


    /**
     * @notes 获取transaction详情
     * @return \think\response\Json
     * @author likeadmin
     * @date 2025/04/09 14:11
     */
    public function detail()
    {
        $params = (new TransactionRecordValidate())->goCheck('detail');
        $result = TransactionRecordLogic::detail($params);
        return $this->data($result);
    }


}